# create（增加）
a = "a"
a = "a" + "b"
print(a)


# retrieve（检索）
# find and index
content = "9876543210"
print(content)
print(content.find("5"))
print(content.index("2"))


# stratswith（首） and endswith（尾）
content = "012345678909876543210"
print(content)
print(content.startswith("01"))
print(content.endswith("10"))


# 索引
content = "abcdefg"
print(content[0])
print(content[3:6])


# update（更新）
# replace（替换）
content = "123123123"
a = content.replace("1", "5")
print(a)


# split（分割）
date_str = "2020-10-29 00:17"
a = date_str.split(" ")
print(a)
b = date_str.split(" ")[0]
print(b)
c = date_str.split(" ")[1]
print(c)


# join(合并）
d = date_str.split(" ")
" " .join("d")
print(d)


# delete(删除）
# strip()两端清除空白字符
a = '  123  '.strip() == '123'
print(a)
content = ' 123 '
b = content.strip()
print(b)
content = '[567]'
c = content.strip('[]')
print(c)

# lstrip()左边清除空白字符
a = '  123'.lstrip() == "123"
print(a)
content = '  268'
a = content.lstrip()
print(a)

# rstrip()右边清除空白字符
a = '123  '.rstrip() == '123'
print(a)
content = '987  '
b = content.rstrip()
print(b)
#字符串格式化输出
#变量
name = 'chunhua'
print(f"{name}-mingshi ")

#传入参数
print("{}-{}-7".format(5, 6))

#指定参数
print("{0},{1},{0}".format("cun", "hua"))

#关键词参数
print("{city}-{name}".format(name="mingshi", city="shanghai"))

#处理浮点数
print("{:.3f}".format(9.38456))

#读取文件
f = open("第二周_第二节tmp.py", "r", encoding="utf-8")
content = f.read()
print(content)
f.close()

#写入文件
f = open("第二周_第二节.py", "w", encoding="utf-8")
print(f.write(content))
f.close()




